package com.cloudkinto.service.company.vo;

import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
public class WarehouseOrderQueryResponse {
    private boolean success = false;

    private Integer errorCode;

    private String errorMsg;
    @ApiModelProperty(value = "系统服务时间，秒级时间戳", required = true)
    private Integer serverTime = Math.toIntExact(DateUtil.currentSeconds());

    private WarehouseOrderQueryResponse.Result result;
    public WarehouseOrderQueryResponse() {
    }
    public WarehouseOrderQueryResponse(Integer errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    @Data
    public static class Result {

        @ApiModelProperty(value = "temu 的批次订单号，可作为幂等健", required = true)
        private String batchOrderNo;
        @ApiModelProperty(value = "订单状态(10：订单处理中，50：订单发运，99：订单作废)", required = true)
        private String orderStatus;
        @ApiModelProperty(value = "仓库编码", required = true)
        private String warehouseCode;
        @ApiModelProperty(value = "物流产品编码", required = true)
        private String logisticsProductCode;
        @ApiModelProperty(value = "订单作废原因")
        private String failReason;
        @ApiModelProperty(value = "包裹详情，订单发运后即状态为 50 必填")
        private List<WarehouseOrderQueryResponse.Package> packageList;

        public Result(String batchOrderNo, String orderStatus, String warehouseCode, String logisticsProductCode) {
            this.batchOrderNo = batchOrderNo;
            this.orderStatus = orderStatus;
            this.warehouseCode = warehouseCode;
            this.logisticsProductCode = logisticsProductCode;
        }

    }

    @Data
    public static class Package {
        @ApiModelProperty(name = "承运商品牌名", required = true)
        private String carrierName;
        @ApiModelProperty(name = "追踪号", required = true)
        private String trackingNumber;
        @ApiModelProperty(name = "发运时间，秒级时间戳", required = true)
        public Integer deliveryTime;
        @ApiModelProperty(value = "订单列表信息", required = true)
        private List<WarehouseOrderQueryResponse.Package.Order> orderList;

        public Package(String carrierName, String trackingNumber, Integer deliveryTime) {
            this.carrierName = carrierName;
            this.trackingNumber = trackingNumber;
            this.deliveryTime = deliveryTime;
        }

        @Data
        public static class Order {
            //Q5、【批次单和 O 单的关系】
            //A：一个批次单下会存在多个 O 单，一个 O 单下会存在多个 SKU，O 单为最小颗粒度，不允许拆单；不
            //同 O 单下也可能存在相同的 SKU，这种情况需要自行合单；
            @ApiModelProperty(name = "O 单列表(不同的 O 单可能存在相同的仓 SKU)", required = true)
            private String orderSn;
            @ApiModelProperty(name = "商品的 skuCode", required = true)
            private String cwSkuCode;
            @ApiModelProperty(name = "商品的sku数量", required = true)
            public Integer qty;

            public Order() {
            }

            public Order(String orderSn, String cwSkuCode, Integer qty) {
                this.orderSn = orderSn;
                this.cwSkuCode = cwSkuCode;
                this.qty = qty;
            }
        }

    }
}
